package com.dbkj.common.interceptor;


import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import io.undertow.server.session.Session;

import javax.servlet.http.HttpSession;

/**
 * @Author: Max
 * @Date: 2019/10/31 17:29
 */

public class SessionInterceptor implements Interceptor {


    @Override
    public void intercept(Invocation invocation) {

        if(invocation.getActionKey().contains("login") || invocation.getActionKey().equals("/")){
            invocation.invoke();
        }else{
            Controller c = invocation.getController();
            HttpSession s = c.getSession(false);
            String username = (String) c.getSession().getAttribute("username");
            if(username!=null){
                invocation.invoke();
            }else{
                c.renderError(403);
            }
        }


    }
}
